
from selenium import webdriver
from selenium.webdriver import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
driver = webdriver.Edge()
driver.maximize_window()

try:
    driver.get("http://121.43.169.97:8848/pageA.html")
    driver.implicitly_wait(5)
    time.sleep(2)
    #   定位元素和输入
    search_box = driver.find_element(By.NAME, "userA")
    search_box.send_keys("admin1")
    time.sleep(2)
    #   对定位元素进行输入框进行一次删除操作
    search_box.send_keys(Keys.BACK_SPACE)
    time.sleep(2)
    #   定义动作链对象
    actions = ActionChains(driver)
    #   右键双击动作链设置和执行
    actions.double_click(search_box).perform()
    time.sleep(2)
    #   模拟键盘的c键点击
    search_box.send_keys(Keys.CONTROL,'c')
    time.sleep(2)
    #   元素定位和模拟键盘的v键点击
    search_box2 = driver.find_element(By.NAME, "passwordA")
    search_box2.send_keys(Keys.CONTROL, 'v')
    time.sleep(2)

except Exception as e:
    print(f"发生错误: {e}")

finally:
    driver.quit()

